<%@page import="org.zty.domain.Attr"%>
<%@page import="org.zty.service.ToServiceStr"%>
<%@page import="org.zty.service.ToPojoStr"%>
<%@page import="org.zty.service.ToHtml"%>
<%@page import="org.zty.service.ToSqlXMLStr"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="org.zty.domain.Pojo"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>

<%
	String pojoname = request.getParameter("pojo_name");
	if (pojoname == null) {
		return;
	}
	Pojo pojo = new Pojo();
	pojo.setName(pojoname);

	String[] attrtypes = request.getParameterValues("attr_type");
	String[] attrnames = request.getParameterValues("attr_name");
	List<Integer> typeList = new ArrayList();
	List<String> nameList = new ArrayList();
	for (String str : attrtypes) {
		if ("".equals(str.trim())) {
			continue;
		}
		if ("string".equals(str.trim().toLowerCase())) {
			typeList.add(1);
		} else if ("int".equals(str.trim().toLowerCase())) {
			typeList.add(2);
		} else if ("date".equals(str.trim().toLowerCase())) {
			typeList.add(3);
		} else {
			typeList.add(4);
		}
	}
	for (String str : attrnames) {
		if ("".equals(str.trim())) {
			continue;
		}
		nameList.add(str);
	}

	if (nameList.size() != typeList.size() || nameList.size() == 0) {
		return;
	}
	List<Attr> attrList = new ArrayList<Attr>();
	for (int i = 0; i < nameList.size(); i++) {
		Attr attr = new Attr();
		attr.setType(typeList.get(i));
		attr.setName(nameList.get(i));
		attrList.add(attr);
	}
	pojo.setAttrList(attrList);

	ToSqlXMLStr tss = new ToSqlXMLStr();
	ToHtml th = new ToHtml();
	ToPojoStr tps = new ToPojoStr();
	ToServiceStr tser = new ToServiceStr();
%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${projectName}</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style>
.textarea_block{
margin:5px;
width:500px;
height:500px;
padding:5px;
line-height:18px;
}
.title{
	line-height:20px;
	height:20px;
	font-size:12px;
	font-weight:bolder;
	padding:0px;
	margin:0px;
	color:#fff;
	/* 如果浏览器不支持渐变，使用图像作为背景 */
	background: #0a246a;
	/* Webkit: Safari 4-5, Chrome 1-9 */
	background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0a246a),
		to(#a6caf0));
	/* Webkit: Safari 5.1+, Chrome 10+ */
	background: -webkit-linear-gradient(left, #0a246a, #a6caf0);
	/* Firefox 3.6+ */
	background: -moz-linear-gradient(left, #0a246a, #a6caf0);
	/* Opera 11.10+ */
	background: -o-linear-gradient(left, #0a246a, #a6caf0);
	/* IE 10 */
	background: -ms-linear-gradient(left, #0a246a, #a6caf0);
	/* IE < 10 */
	/* 注意：这一行必须写在最后 ,gradientType=0 纵向 1 横向*/
	FILTER: progid:DXImageTransform.Microsoft.Gradient(startColorStr=#0a246a,
		endColorStr=#a6caf0, gradientType=1);
}
.title_text{
	margin-left:5px;
}
.outer_block{
	margin-top:5px;
	margin-left:5px;
	float:left;
	background:#d4d0c8;
}
</style>
<script>
</script>
</head>

<body style="">


	<div class="outer_block">
		<p class="title">
			<span class="title_text">建表语句</span>
		</p>
		<textarea class="textarea_block"><%=tss.createTable(pojo)%></textarea>
	</div>
	<div class="outer_block">
			<p class="title">
				<span class="title_text"> sqlmap.xml</span>
			</p>

			<textarea class="textarea_block" style="width:900px;"><%=tss.toSqlXML(pojo)%></textarea>
		</div>
		<div style="height:20px;clear:both"></div>
		<div class="outer_block">
			<p class="title">
				<span class="title_text"> pojo</span>
			</p>
			<textarea class="textarea_block"><%=tps.toPojoStr(pojo)%></textarea>
		</div>
		
		<div class="outer_block">
			<p class="title">
				<span class="title_text"> DAO/service</span>
			</p>
			<textarea class="textarea_block"><%=tser.toService(pojo)%></textarea>
		</div>
		
		<div class="outer_block">
			<p class="title">
				<span class="title_text">action/_do.jsp</span>
			</p>
			<textarea class="textarea_block"><%=th.toJsp(pojo)%></textarea>
		</div>
		<div style="height:20px;clear:both"></div>
		
		<div class="outer_block">
			<p class="title">
				<span class="title_text"> ListTable列表页面</span>
			</p>
			<textarea class="textarea_block"><%=th.toList(pojo)%></textarea>
		</div>
		<div class="outer_block">
			<p class="title">
				<span class="title_text"> addFormTable新增页面</span>
			</p>
			<textarea class="textarea_block"><%=th.toAddForm(pojo)%></textarea>
		</div>
		<div class="outer_block">
			<p class="title">
				<span class="title_text"> updateFormTable修改页面</span>
			</p>
			<textarea class="textarea_block"><%=th.toUpdateForm(pojo)%></textarea>
		</div>
		<div style="height:20px;clear:both"></div>
	</body>
</html>
